//
// Created by DengLibin on 2019/1/1 0001.
//

//
// Created by DengLibin on 2019/1/1 0001.
//

//
// Created by DengLibin on 2019/1/1 0001.
//

//
// Created by DengLibin on 2019/1/1 0001.
//

//
// Created by DengLibin on 2018/12/31 0031.
//

//
// Created by DengLibin on 2018/12/29 0029.
//

#include <wx/app.h>
#include <wx/wx.h>
#include <wx/progdlg.h>
#include <wx/busyinfo.h>
#include <wx/wxprec.h>
#include <string>
#include <wx/dcbuffer.h>
using namespace std;
/**
 * 进度对话框
 */
class Demo9Frame : public wxFrame
{
private:
    //声明事件表
wxDECLARE_EVENT_TABLE();


public:
    Demo9Frame(string & title):wxFrame(nullptr, wxID_ANY, title)
    {
        initPosition();
    }

    void initDialog(){
       static  const int max = 100;
       wxProgressDialog * progressDialog = new wxProgressDialog(wxT("进度..."), wxT("进行中"),
               max, this);
       bool cont = true;
       for(int i = 0; i <= 100; i++){
           wxMilliSleep(50);
           if(i == max){
               cont = progressDialog->Update(i,wxT("完成"));
           }else if( i == max / 2){
               cont = progressDialog->Update(i,wxT("一半了"));
           }else{
               cont = progressDialog->Update(i);
           }
       }
       progressDialog->Resume();
       delete progressDialog;
       if(!cont){
           wxMessageBox(wxT("终止了"));
       }else{
           wxMessageBox(wxT("完成了"));
       }

    }

    void initPosition(){
        //设置窗口位置
        wxPoint position;
        position.x = 300;
        position.y = 300;
        SetPosition(position);
        //设置背景色
        wxColour backGroundColor(0,100,0);
        SetBackgroundColour(backGroundColor);
        //设置宽高
        this->m_minWidth = 800;
        this->m_minHeight = 600;
    }

};


class Demo9App:public wxApp
{
    bool OnInit()
    {
        string title = "Demo9";
        //  wxFrame * frame = new wxFrame(NULL, wxID_ANY, "第一个窗体");
        Demo9Frame * frame = new Demo9Frame(title);
        frame->Show();
        frame->initDialog();
        return true;
    }
};
//事件和函数绑定
wxBEGIN_EVENT_TABLE(Demo9Frame, wxFrame)
wxEND_EVENT_TABLE()

// 有了这一行就可以使用 OurApp& wxGetApp了()
DECLARE_APP(Demo9App)
//告诉主应用程序是哪个类wxWidgets（启动）
//IMPLEMENT_APP(Demo9App)
